package com.xy

import android.graphics.Bitmap
import android.graphics.Matrix
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import java.security.MessageDigest

/**
 * @ClassName RotateTransformation
 * @Author xy
 * @Date 2021/8/20 15:11
 * @Description 图片旋转帮助类
 */
class RotateTransformation: BitmapTransformation {

    //旋转默认0
    private var rotateRotationAngle = 0f

    constructor(rotateRotationAngle: Float) {
        this.rotateRotationAngle = rotateRotationAngle
    }

    override fun updateDiskCacheKey(messageDigest: MessageDigest) {

    }

    override fun transform(
        pool: BitmapPool,
        toTransform: Bitmap,
        outWidth: Int,
        outHeight: Int
    ): Bitmap {
        val matrix = Matrix()
        //旋转
        //旋转
        matrix.postRotate(rotateRotationAngle)
        //生成新的Bitmap
        //生成新的Bitmap
        return Bitmap.createBitmap(
            toTransform,
            0,
            0,
            toTransform.width,
            toTransform.height,
            matrix,
            true
        )

    }


}